import axios from '@/libs/api.request'

export const getApiNames = (val) => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/names/',
    params: val,
    method: 'get'
  })
};

export const getApis = (val) => {
  return axios.request({
    url: 'api/HttpAutoTestService/apis/',
    params: val,
    method: 'get'
  })
};

export const getApiById = (id) => {
  return axios.request({
    url: `api/HttpAutoTestService/apis/${id}/`,
    method: 'get'
  })
};

export const createApi = (api) => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/',
    data: api,
    method: 'post'
  })
};

export const updateApi = (api) => {
  return axios.request({
    url: `api/HttpAutoTestService/api/${api.id}/`,
    data: api,
    method: 'put'
  })
};

export const batchDeleteApi = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/batch_delete/',
    method: 'delete',
    data: data
  })
};

export const importApiFile = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/import/',
    method: 'post',
    data: data
  })
};

export const moveApi = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/move/',
    data: data,
    method: 'post'
  })
};

export const downloadApiTemplate = () => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/template/download/',
    method: 'get',
    responseType: 'arraybuffer'
  })
};

export const uploadApiFile = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/upload/',
    method: 'post',
    data: data
  })
};

export const debugApi = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/debug/',
    method: 'post',
    data: data
  })
};

export const batchCreateApiAndTestcase = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/api/batch_create/',
    method: 'post',
    data: data
  })
};